import datetime
import random
money=5000
product=[{"name":"AC","price":2000},{"name":"fridge","price":2500},
         {"name":"TV","price":3000},{"name":"wm","price":3500},
         {"name":"mo","price":1500},{"name":"oven","price":1000},
         {"name":"wh","price":2200},{"name":"ef","price":4000},
         {"name":"ei","price":1000},{"name":"juicer","price":4500}]
shopping_cart=[]
coupon=[{"name":"AC","discount":0.8},{"name":"fridge","discount":0.9},
         {"name":"TV","discount":0.7},{"name":"wm","discount":0.9},
         {"name":"mo","discount":0.85},{"name":"oven","discount":0.95},
         {"name":"wh","discount":0.65},{"name":"ef","discount":0.7},
         {"name":"ei","discount":0.5},{"name":"juicer","discount":0.8}]
print("请抽取优惠券:")
coupons = random.choice(coupon)
print(f"抽到的优惠券为:{coupons}")
if coupon:
    use = input("是否使用优惠券?(y/n)")
    if use=='y':
        if "discount" in coupon:
            final_price=product["price"]*coupon["discount"]
            print(f"折扣后价格:{final_price}")
    else:
        print("未使用优惠券,原价购买商品")
while True:
    product_name = input('请输入要购买的商品名称:')
    if product_name == 'q':
        break
    found = False
    for item in product:
        if item["name"] == product_name:
            found = True
            if money >= item["price"]:
                shopping_cart.append(item)
                money -= item["price"]
                print(f"恭喜，购买成功,余额为{money}")
            else:
                print("穷鬼，钱不够!请到其他超市购买!")
            break
    if not found:
        print("没有这个商品，别瞎弄!")
    print("购买小票")
    print(f"购买时间:{datetime.datetime.now()}")
    print(f"卡余额:{money}")
    purchase_quantity=len(shopping_cart)
    print(f"购买数量:{purchase_quantity}")
    total_value = sum(product["price"]
                              for product in shopping_cart)
    print(f"总商品的价值:{total_value}")
    function=input("请输入要退货的商品:")
    print(f"{function}商品已退回购物架中")
    break
    for product in shopping_cart:
                shopping_cart.pop(product)
                print(f"{function}商品已退回购物架中")




